package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Lteratore {
    public static void main(String[] args) {
        Collection<String> c = new ArrayList<>();
        c.add("one");
        c.add("#");
        c.add("two");
        c.add("three");

        Iterator<String> it = c.iterator();
        while (it.hasNext()) {
            String e = it.next();
            if (e.equals("#")) {
                c.remove(e); // 使用Iterator的remove方法来安全地移除元素
            }
            System.out.println(e);
        }
        System.out.println(c);
    }
}